/*
ID:luongho3
LANG:C++
TASK:checker
*/
#include <iostream>
#include <fstream>

using namespace std;
#define SIZE 14
int row[SIZE],col[SIZE],lr_dia[2*SIZE],rl_dia[2*SIZE];
int sol[SIZE];
int N;
int nSol;
ifstream fin("checker.in");
ofstream fout("checker.out");

int lr_index(int n) {
    return n + N;    
}
int rl_index(int n) {
    return n - 1;
}
/*void init() {
     int i,j;
     for (i=0;i<SIZE;++i) {
         row[i] = 0;
         col[i] = 0;
         sol[i] = 0;
         lr_dia[i] = 0;
         rl_dia[i] = 0;
     }
     for (;i<2*SIZE;++i) {
         lr_dia[i] = 0;
         rl_dia[i] = 0;
     }
}*/
void printSol() {
     int i;
     for (i=1;i<=N;++i) {
         fout << sol[i];
         if (i<N) fout << " ";
     }
}
void tryAt(int c) {
     if (c>N) {
        nSol++;
        if (nSol<=3) {
           printSol();
           fout << "\n";
        }
     }
     int i,j,rl,lr;
     for (i=1;i<=N;++i) {
         if (N>6) {
             if (c==1) {
                if (N%2 == 0) {
                   if (i == N/2 + 1) {
                      nSol *= 2;
                      break;
                   }
                }
                else {
                     if (i == N/2 + 1) {
                        nSol *= 2;
                     }
                     else if (i == N/2 + 2) {
                          break;
                     }
                }
             }
         }
         rl = rl_index(i + c);
         lr = lr_index(i - c);
         if (row[i]!=1 && col[c]!=1 && rl_dia[rl]!=1 && lr_dia[lr]!=1) {
            sol[c] = i;
            row[i] = col[c] = rl_dia[rl] = lr_dia[lr] = 1;
            tryAt(c+1);
            row[i] = col[c] = rl_dia[rl] = lr_dia[lr] = 0;
            sol[c] = 0;
         }
     }
}
int main() {
    fin >> N;
    //init();
    nSol = 0;
    tryAt(1);
    fout << nSol << "\n";
    return 0;    
}
